<template>
  <div>
    <div style="margin-top: -90px;margin-bottom: -20px">修改政策</div>
    <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px">
      <div style="margin-right: 125px;margin-left: 55px">
        <el-form-item label="政策标题" prop="title" >
          <el-input v-model="ruleForm.title"></el-input>
        </el-form-item>
        <el-form-item label="政策内容" prop="message">
          <el-input v-model="ruleForm.message"></el-input>
        </el-form-item>
      </div>
      <el-form-item style="margin-left: -90px">
        <el-button type="primary" @click="submitForm('ruleForm')">修改</el-button>
        <el-button @click="resetForm('ruleForm')">重置</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import {editPolicy} from "@/api/policy";

export default {
  data() {
    return {
      ruleForm: {
        id:'',
        title:'',
        message:'',
      },
      rules: {
        title: [{ required: true, message: '请输入政策标题', trigger: 'blur' },],
        message: [{ required: true, message: '请输入政策内容', trigger: 'blur' },]
      }
    };
  },
  props:["myForm"],
  methods: {
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          editPolicy(this.ruleForm).then(res=>{
            if(res.code==200){
              //修改成功
              this.$message({type:'success',message:res.msg})
              this.$emit("closeEditDialog")
            }else{
              //修改失败
              this.$message({type:'error',message:res.msg})
            }
          }).catch(error=>{})
        } else {
          console.log('error submit!!');
          return false;
        }
      });
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
    },
    showData(){
      this.ruleForm.id=this.myForm.id
      this.ruleForm.title=this.myForm.title
      this.ruleForm.message=this.myForm.message
    }
  }
}
</script>

<style scoped>

</style>
